//
//  CJTGoodTableViewCell.m
//  BreadTravel
//
//  Created by dllo on 15/12/25.
//  Copyright © 2015年 蓝鸥科技. All rights reserved.
//

#import "CJTGoodTableViewCell.h"

@implementation CJTGoodTableViewCell


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self)
    {
        [self createSubViews];
    }
    return self;
}

- (void)createSubViews
{
    UIView *imageView = [[UIView alloc] initWithFrame:CGRectMake(15, 15, WIDTH - 30, 140)];
    imageView.backgroundColor = [UIColor colorWithRed:0.97 green:0.97 blue:0.92 alpha:1];
    imageView.layer.cornerRadius = 8;
    imageView.layer.masksToBounds = YES;
    [self.contentView addSubview:imageView];
    
    self.cover_image_1600 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, imageView.W , imageView.H )];
    [imageView addSubview:self.cover_image_1600];
    
    UIImageView *blackImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, imageView.W , imageView.H )];
    blackImageView.image = [UIImage imageNamed:@"trip_map_cover@2x~ipad.png"];
    [imageView addSubview:blackImageView];//trip_map_cover@2x~ipad.png
    
    UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(15, 15, WIDTH - 30, 140)];
    bgView.backgroundColor = [UIColor blackColor];
    bgView.alpha = 0.0;
    bgView.layer.cornerRadius = 8;
    bgView.layer.masksToBounds = YES;
    [self.contentView addSubview:bgView];
    
    //渐变
    self.gradientLayer = [CAGradientLayer layer];//创建
    self.gradientLayer.frame = blackImageView.frame; //类似一张图
    [self.imageView.layer addSublayer:self.gradientLayer];//添加
    
    
    
    //设置渐变颜色方向  (x=0 y=1 w=0 z=0 ) 表示从上到下的渐变
    //(x=0  y=0 w=0  z=1 ) 表示从下到上的渐变
    self.gradientLayer.startPoint = CGPointMake(0, 0);//(x,y)
    self.gradientLayer.endPoint = CGPointMake(0, 1);//(w,z)
    //设定颜色组
    self.gradientLayer.colors = @[(__bridge id)[UIColor clearColor].CGColor,
                                  (__bridge id)[UIColor blackColor].CGColor];
    //设定颜色分割点 (第一个括号里 点几 表示浓度)
    self.gradientLayer.locations = @[@(0.1f) ,@(1.0f)];



    self.name = [[UILabel alloc] initWithFrame:CGRectMake(self.cover_image_1600.X+15, self.cover_image_1600.Y+15, 281, 41)];
    self.name.font = [UIFont boldSystemFontOfSize:17];
    self.name.textColor = [UIColor whiteColor];
    self.name.lineBreakMode = NSLineBreakByCharWrapping;
    // 显示行数，0表示无限行
    //    self.name.numberOfLines = 0;
    [imageView addSubview:self.name];
    
    
    

    UIView *backView = [[UIView alloc] initWithFrame:CGRectMake(self.name.X, self.name.Y+self.name.H-10, 3, 8)];
    backView.backgroundColor = [UIColor redColor];
//    //裁掉边框
//    backView.layer.masksToBounds = YES;
//    //设置半径
//    backView.layer.cornerRadius = 5;
    [imageView addSubview:backView];
    
    
    
    
    self.day_count = [[UILabel alloc] initWithFrame:CGRectMake(backView.X+backView.W +4, backView.Y-4 , 300, 15)];
    self.day_count.font = [UIFont boldSystemFontOfSize:12];
    self.day_count.textColor = [UIColor whiteColor];
    [imageView addSubview:self.day_count];
//    self.day_count.textColor = [UIColor lightGrayColor];
    
    
    
    UIImageView *stripImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, imageView.H-37, imageView.W , 20)];
    stripImage.image = [UIImage imageNamed:@"phone_dest_trip_info_bg.png"];
    [imageView addSubview:stripImage];
    stripImage.alpha = 0.4;
    
    
    UIView *wayView = [[UIView alloc] initWithFrame:CGRectMake(self.name.X, stripImage.Y+6, 6, 6)];
    wayView.backgroundColor = [UIColor colorWithRed:0.24 green:0.76 blue:0.78 alpha:1];
    //裁掉边框
    wayView.layer.masksToBounds = YES;
    //设置半径
    wayView.layer.cornerRadius = 3;
    [imageView addSubview:wayView];

    self.waypoints = [[UILabel alloc] initWithFrame:CGRectMake(wayView.X+wayView.W +5, wayView.Y-2, 50, 12)];
    self.waypoints.font = [UIFont boldSystemFontOfSize:12];
    self.waypoints.textColor = [UIColor whiteColor];
    [imageView addSubview:self.waypoints];
    
    
    
    
    UIView *recomdView = [[UIView alloc] init];
    //裁掉边框
    recomdView.layer.masksToBounds = YES;
    //设置半径
    recomdView.layer.cornerRadius = 3;
    [imageView addSubview:recomdView];
    
    [recomdView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(wayView.mas_top);
        make.left.equalTo(self.waypoints.mas_right).offset(5);
        make.height.equalTo(wayView.mas_height);
        make.width.equalTo(wayView.mas_width);
    }];
    recomdView.backgroundColor = [UIColor colorWithRed:0.24 green:0.76 blue:0.78 alpha:1];
    
    self.recommendations = [[UILabel alloc] init];
    [imageView addSubview:self.recommendations];
    [self.recommendations mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.waypoints.mas_top);
        make.left.equalTo(recomdView.mas_right).offset(5);
        make.bottom.equalTo(self.waypoints.mas_bottom);
    }];
    self.recommendations.font = [UIFont boldSystemFontOfSize:12];
    self.recommendations.textColor = [UIColor whiteColor];
    
    
    
    
    
}

-(void)setModel:(CJTGoodModel *)model
{

    self.name.text = model.name;
    [self.name sizeToFit];
    
    NSDate *shijian = [NSDate dateWithTimeIntervalSince1970:model.date_added];
   
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    //设置时间格式
    [formatter setDateFormat:@"yyyy-MM-dd"];
    //date转化成字符串
    NSString *dateStr = [formatter stringFromDate:shijian];
    
    self.day_count.text = [NSString stringWithFormat:@"%@ %ld天", dateStr, model.day_count];
    self.waypoints.text = [NSString stringWithFormat:@"%ld足迹", (long)model.waypoints];
    self.recommendations.text = [NSString stringWithFormat:@"%ld喜欢", (long)model.recommendations];
    NSURL *url = [NSURL URLWithString:model.cover_image_1600];
    [self.cover_image_1600 sd_setImageWithURL:url placeholderImage:IMAGE];

}




/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
